feat[libcpu][cortex-m4]: Detect interrupt context from IPSR on Cortex-M4#11316
feat[libcpu][cortex-m4]: Detect interrupt context from IPSR on Cortex-M4#11316Rbb666 merged 2 commits intoRT-Thread:masterfrom
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
3c42e32 to
d6f326a
Compare
📌 Code Review Assignment🏷️ Tag: kernelReviewers: GorrayLi ReviewSun hamburger-os lianux-mm wdfk-prog xu18838022837 Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-04-08 13:50 CST)
📝 Review Instructions
|
There was a problem hiding this comment.
Pull request overview
This PR aims to make “interrupt context” detection on Cortex-M4 explicit (via IPSR), reduce direct scheduler coupling to rt_interrupt_nest, and complete Cortex-M4-side interrupt hook/IRQ-mask query support.
本 PR 目标是在 Cortex-M4 上显式化“中断上下文”识别(基于 IPSR),降低调度器对 rt_interrupt_nest 的直接耦合,并补齐 Cortex-M4 侧的中断 hook / 中断屏蔽状态查询能力。
Changes:
- Replace
src/scheduler_up.cdirect dependency onrt_interrupt_nestwithrt_interrupt_get_nest(). - Expose interrupt enter/leave hook function pointers for platform-side reuse.
- Add Cortex-M4 implementations for
rt_interrupt_enter/leave,rt_interrupt_get_nest(), andrt_hw_interrupt_is_disabled().
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/scheduler_up.c |
Switch interrupt-context checks/logging to rt_interrupt_get_nest() instead of rt_interrupt_nest. |
src/irq.c |
Make interrupt enter/leave hook pointers globally visible (non-static). |
libcpu/arm/cortex-m4/cpuport.c |
Add IPSR/PRIMASK helpers and Cortex-M4 overrides for IRQ enter/leave, nest query, and IRQ-disabled query. |
d6f326a to
de3622f
Compare
拉取/合并请求描述:(PR description)
为什么提交这份 PR (why to submit this PR)
当前补丁的核心目标,是将 Cortex-M4 平台上的中断上下文识别与相关 hook 调用路径显式化,并减少调度器对外部中断嵌套计数变量的直接耦合。
现有实现中,
scheduler_up.c直接依赖rt_interrupt_nest判断当前是否处于中断上下文;而在 Cortex-M4 平台上,这类信息本身可以直接通过IPSR寄存器判断。与此同时,本补丁还补充了rt_interrupt_enter()/rt_interrupt_leave()的平台侧实现,以及中断屏蔽状态查询接口rt_hw_interrupt_is_disabled(),使 Cortex-M4 平台上的中断相关行为更完整、更清晰。因此提交本 PR,以完善 Cortex-M4 架构下的中断上下文识别能力、补齐中断 enter/leave hook 调用链,并将调度器中的中断态判断改为通过统一接口获取,降低对内部变量的直接依赖。
你的解决方案是什么 (what is your solution)
本 PR 主要做了以下修改:
补充 Cortex-M4 中断上下文识别能力
libcpu/arm/cortex-m4/cpuport.c中新增__get_IPSR();IPSR实现rt_interrupt_get_nest();补充 Cortex-M4 中断 enter/leave 路径
cpuport.c中新增rt_interrupt_enter();cpuport.c中新增rt_interrupt_leave();rt_interrupt_enter_hookrt_interrupt_leave_hook暴露中断 hook 指针供平台侧使用
src/irq.c中,将:rt_interrupt_enter_hookrt_interrupt_leave_hook从文件内
static变量改为全局可见符号;增加中断屏蔽状态查询接口
cpuport.c中新增rt_hw_get_primask_value();PRIMASK实现rt_hw_interrupt_is_disabled();调整调度器中的中断态判断方式
src/scheduler_up.c中移除对rt_interrupt_nest的直接 extern 依赖;rt_interrupt_get_nest();请提供验证的 BSP 和 config (provide the config and bsp)
BSP:
bsp/stm32/stm32f407-atk-explorer.config:
CONFIG_ARCH_ARM_CORTEX_M4CONFIG_RT_USING_HOOK验证方式:
rt_interrupt_get_nest()返回 0;rt_interrupt_get_nest()返回非 0;rt_interrupt_enter()/rt_interrupt_leave()能正常触发 hook;rt_schedule()在中断上下文下不会走线程态切换路径;rt_hw_interrupt_is_disabled()在关中断/开中断场景下返回值符合预期。action:
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up